﻿using NUnit.Framework;
using NMA.Infrastructure.NHibernate.CriteriaExpression;
using NMA.Domain.Model.Contract;
using System;
using NMA.Domain.Model;
using NMA.Infrastructure.NHibernate.DomainObject;

namespace NMA.Infrastructure.NHibernate.Tests.CriteriaExpression
{
    [TestFixture]
    public class SearchCategoryCriteriaExpressionTest : TestingBase
    {
        private CategorySearchCriteria model;
        private ICategory testingCategory;
        public CriteriaExpressionFactory CriteriaFactory { get; set; }

        protected override void Before_each_test()
        {
            base.Before_each_test();
            CriteriaFactory = new CriteriaExpressionFactory();

            model = new CategorySearchCriteria()
            {
                Id = Guid.NewGuid(),
                Name = "testName",
                CreatedUser = "testUser",
                CreatedDate = DateTime.Now
            };

            testingCategory = new Category()
            {
                Id = Guid.NewGuid(),
                Name = "testName",
                CreatedUser = "testUser",
                UpdatedUser = "testUser",
                CreatedDate = DateTime.Now,
                UpdatedDate = DateTime.Now,
            };
        }

        protected override void After_each_test()
        {
            base.After_each_test();
            if (CriteriaFactory != null)
                GC.SuppressFinalize(CriteriaFactory);
        }

        [Test]
        public void GetIdFunctionTest()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.Id);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == false);
        }

        [Test]
        public void GetNameFunctionTest()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.Name);
            var funcSearch1 = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.Name);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == true);
        }

        [Test]
        public void GetCreatedDateFunctionTest()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.CreatedDate);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == true);
        }

        [Test]
        public void GetIdAndNameFuncTest()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.Id | SearchCategoryCriteriaType.Name);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == false);
        }

        [Test]
        public void GetIdAndCreatedUserTest()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.Id | SearchCategoryCriteriaType.CreatedUser);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == false);
        }

        [Test]
        public void GetIdAndNameAndCreatedUserAndCreatedDateTest()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model, SearchCategoryCriteriaType.All);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == false);
        }

        [Test]
        public void GetIdAndNameAndCreatedUserAndCreatedDateTestWithTwoParametters()
        {
            var funcSearch = CriteriaFactory.CreateCategorySearchCriteria(model);
            var result = funcSearch(testingCategory);
            Assert.IsTrue(result == false);
        }
    }
}